package com.topcheer.gateway.ribbon.db.rule;

import com.netflix.loadbalancer.Server;
import com.topcheer.gateway.ribbon.WeightRoundRibbon;
import com.topcheer.gateway.ribbon.WeightServer;
import com.topcheer.gateway.ribbon.context.RibbonFilterContext;
import com.topcheer.gateway.ribbon.context.RibbonFilterContextHolder;

import java.util.List;

/**
 * @author xutao
 * @Package com.topcheer.gateway.ribbon.db.rule
 * @Description: ${todo}
 * @date 2020/9/25 16:09
 */
public class WeightRoundRule {

    WeightRoundRibbon weightRoundRibbon;

    public WeightRoundRule(WeightRoundRibbon weightRoundRibbon) {
        this.weightRoundRibbon = weightRoundRibbon;
    }

    public Server choose(List<WeightServer> serverList) {
        WeightServer server = weightRoundRibbon.getServer(serverList);
        final RibbonFilterContext context = RibbonFilterContextHolder.getCurrentContext();
        context.put("serverType", server.getType());
        return server;
    }
}
